<template>
	<div class="wpsz">
		<div class="wpszlt">
			<div class="wpfl" @click="getcomboxlist()">参数类别</div>
			<div v-for='v in comboxlist' :class="v.classname">
				<div class="jclt" @click="wpfxbtnclick(v.cd ,v.cdname)">{{v.cdname}}</div>
			</div>
		</div>
		<div class="port-page">
			<!-- 顶部按钮 -->
			<div class="but1">
				<router-link to="/home">
					<el-button type="warning" size="small" class="add btn" style='margin-right: 5px;' icon="el-icon-menu">首页</el-button>
				</router-link>
				<el-button type="success" size="small" class="add btn" style='margin-top:10px;' @click='componentsShow("add","")' icon="el-icon-edit">添加</el-button>
			</div>
			<!-- 模糊搜索条件 -->
			<div class="search">
				<div class="search-item" style="margin-left: 10px;">
					<el-tooltip  placement="top" class="sx"  >
  				<el-switch  @change="search()" v-model="visenable" active-color="#13ce66" inactive-color="#ff4949" inactive-text="禁用" active-text="启用" active-value="Y" inactive-value="N"></el-switch>
  			</el-tooltip>
				</div>
				<!--<div class="search-item">
					<span></span>
					<el-input placeholder="输入物品名称检索" class="code-search" v-model="vkeyword" @keyup.enter.native="search" icon="el-icon-search"></el-input>
				</div>-->
				<!--<el-button type="primary" class="add btn" style='border-radius: 13px;' :loading="searchLoading" @click="search" icon="el-icon-search"></el-button>-->

			</div>
			<!-- 数据表格展示区域 -->
			<el-table :data="dataList" border stripe size="small " align="left" class="admin-table" @select="checkSelect" style="width: 100%" @select-all="checkall">
				<div slot='empty'>
					<img src="../../../assets/img/empty.png" style="width:40px;vertical-align: middle;">
					<span style="vertical-align: middle;">暂时还没有内容哦!</span>
				</div>
				<el-table-column :prop="v.prop" :label="v.label" v-for="(v,index) in portTitleList" align="center" show-overflow-tooltip v-if="v.hide != 0" :formatter="v.formatter" :align="v.align || 'center'" :fixed="v.fixed" :class-name="v.columnStyle" :width="v.width" :min-width="v.minWidth" :header-align="v.headerAlign || 'center'">
					<template scope="scope">
						<div slot="reference" :style="tableCellControl(scope)">
							{{ scope.row[scope.column.property] }}
						</div>
					</template>
				</el-table-column>
				<el-table-column label="标签" v-if="this.vpcdname=='作业类型'" align="center">
				<template scope="scope">
					<el-button size="small" type="text" style="color:#1F2D3D">{{scope.row.bq}}</el-button>
				</template>
			    </el-table-column>
			    <el-table-column label="标签" v-if="this.vpcdname=='考试类型'" align="center">
				<template scope="scope">
					<el-button size="small" type="text" style="color:#1F2D3D">{{scope.row.bq}}</el-button>
				</template>
			    </el-table-column>
				<el-table-column fixed="right" align="center" label="操作" width="150px">
					<template scope="scope">
					 	<el-button size="mini" type="warning" @click="componentsShow('edit',scope)">编辑</el-button>
                        <el-button size="mini" type="danger" @click="componentsShow('singleDelete',scope)">删除</el-button>
					</template>
				</el-table-column>
			</el-table>
			<!-- 各个组件显示区域 -->
			<!-- 动画加载 -->
			<LoadingComponent v-show="isLoading"></LoadingComponent>
			<!-- 添加组件 -->
			<AddComponent v-if="portComponents.add.toggle" @close="componentsHide" :params="portComponents.add.params"></AddComponent>
			<!-- 编辑组件 -->
			<EditComponent v-if="portComponents.edit.toggle" @close="componentsHide" :params="portComponents.edit.params"></EditComponent>
			<!-- 单独删除组件 -->
            <DeleteComponent v-if="portComponents.singleDelete.toggle"  @close="componentsHide"  :data="portComponents.singleDelete.data"></DeleteComponent>
			<!-- 子路由显示区域 -->
			<router-view class="port-view"></router-view>
		</div>
	</div>
</template>
<script>
	import { mapState } from 'vuex'
	import LoadingComponent from 'components/loading'
	import AddComponent from './add'
	import EditComponent from './edit'
	import DeleteComponent from './del'
	import qs from 'qs'
	export default {
		components: {
			LoadingComponent,
			AddComponent,
			EditComponent,
			DeleteComponent
		},
		data() {
			return {

				/*模糊搜索条件*/
				visenable:'Y',
				vkeyword: '', // keyword
				vpcd: '',
				vpcdname: '',
				multipleDelNum: '', //获取批量选择的数据
				dataList: [], //表格数据
				comboxlist: [], //下拉框 动态的

				/*动画加载*/
				isLoading: true, //动画加载
				searchLoading: false, //搜索按钮触发按钮动画
				/*分页属性设置*/
				layout: 'total, sizes, prev, pager, next, jumper', //组件布局
				pageindex: this.$store.state.pageindex, //当前分页页码
				pagesizes: this.$store.state.pagesizes, //显示个数的选择器选项
				pagesize: this.$store.state.pagesize, //每页显示条目数
				total: 0, //总条数

				/*组件区域*/
				portComponents: {
					/* 单行删除  */
					singleDelete: {
						type: 'singleDelete',
						toggle: false,
						params: '',
						data: {
							index: '',
							type: 'single',
							title: '此操作将删除该记录?, 是否继续?'
						}
					},
					/* 添加 */
					add: {
						type: 'add',
						toggle: false,
						params: '',
						data: {},
						flid: '',
					},
					/* 编辑 */
					edit: {
						type: 'edit',
						toggle: false,
						params: '',
						data: {}
					},
					del: {
						type: 'del',
						toggle: false,
						params: '',
						data: {}
					}
				},
				/*
				    prop :  接口参数名
				    label : 接口中文名
				    hide : 是否隐藏这一列
				    align : 这一列对齐顺序 ： left,right,center
				    headerAlign : 这一列表头对齐方式 ： left,right,center
				*/
				portTitleList: [ 
					{
						prop: 'id',
						label: '物品id',
						hide: 0,
						align: 'center',
						fixed: false,
						width: '',
						minWidth: '',
						headerAlign: 'center',
						formatter: function(row, column) {}
					}, 
					{
						prop: 'cdname',
						label: '项目名称',
						hide: 1,
						align: 'center',
						fixed: false,
						width: '',
						minWidth: '',
						headerAlign: 'center',
						formatter: function(row, column) {}
					} 
				]
			}
		},
		created() {
			var logininfo = JSON.parse(localStorage.logininfo);
			//加载页面时调用
			this.$store.dispatch('changeTitle', '基础参数设置'); //修改title
			this.$store.dispatch('changeRouterIndex', '/admin/xtcs'); //修改路由
			this.isLoading = true; //动画开始
			this.getcomboxlist(); //加载下拉/
			
		},
		mounted() {
			//加载完成之后event
			this.isLoading = false; //动画结束
		},
		methods: {
			wpfxbtnclick(wpfxid, vpcdname) {
				this.vpcd = wpfxid;
				this.vpcdname = vpcdname;
				for(let i in this.comboxlist) {
					this.comboxlist[i].classname = 'jc';
					if(this.comboxlist[i].cd == this.vpcd) {
						this.comboxlist[i].classname = 'jc2';
					}
				}
				this.search();
			},
			search() {
				//查询搜索触发事件
				var logininfo = JSON.parse(localStorage.logininfo);
				this.searchLoading = true;
				var params2 = qs.stringify({
					isenable: this.visenable,
					pcd: this.vpcd ,
					yhid: logininfo.id,
					xxid: logininfo.xxid,
				})
				//执行
				this.axios.post(this.$store.state.api + 'xxcode/list', params2)
					.then(res => {
						let data = res.data.data;
						let list = data.list;
						this.total = data.totalPage;
						this.dataList = list;
						this.searchLoading = false;
					}).catch(res => {
						this.searchLoading = false;
					})
			},
			getcomboxlist() {
				var logininfo = JSON.parse(localStorage.logininfo);
				this.searchLoading = true;
				var params2 = qs.stringify({
					yhid: logininfo.id,
					xxid: logininfo.xxid
				})
				//执行
				this.axios.post(this.$store.state.api + 'xxcode/getfllist', params2)
					.then(res => {
						this.flid = res.data.data.list[0].cd;
						this.vpcdname = res.data.data.list[0].cdname;
						//this.wpfxbtnclick(this.flid, this.vpcdname);
						let data = res.data.data;
						let list = data.list;
						var icnt =0;
						for(let i in list) {
							list[i].classname = 'jc';
							if(list[i].cd == this.vpcd) {
								list[i].classname = 'jc2';
								icnt=1;
							}
						} 
						if (icnt==0){ 
							this.vpcd=list[0].cd ; 
						    list[0].classname = 'jc2';
						}
						this.comboxlist = list;
						this.search(); //分页获取默认数据
					}).catch(res => {
						this.searchLoading = false;
					})
			},
			tableCellControl(scope) {
				//表格单元格控制CSS样式
				/*if (scope.row.id == 112 && scope.column.property == "iname") {
				    return {
				        color:"red",
				    }
				}else{
				    return {
				        color:"green",
				    }
				}*/
			},
			handleSizeChange(val) { //每页显示条数触发事件
				this.pagesize = val;
				this.pageindex = 1;
				this.search();
			},
			handleCurrentChange(val) { //分页触发事件
				this.search();
			},
			checkSelect(selection, row) { //点击单选select触发事件
				this.multipleDelNum = selection
//				if(this.multipleDelNum.length>0) {
//					this.multipleDeleteDisabled = false
//				} else {
//					this.multipleDeleteDisabled = true
//				}

			},
			checkall(selection) { //点击全选select触发事件
				this.multipleDelNum = selection
//				if(this.multipleDelNum.length>0) {
//					this.multipleDeleteDisabled = false
//				} else {
//					this.multipleDeleteDisabled = true
//				}
			},
			/* 组件的弹框  */
			componentsShow(type, data) { //显示组件

				for(let i in this.portComponents) {
					if(type == this.portComponents[i].type) {
						this.portComponents[i].toggle = true;
						this.portComponents[i].params = data;
						if(this.portComponents[i].data.type == 'single') {
							this.portComponents[i].data.index = data.row.id
						} else if(this.portComponents[i].data.type == 'multiple') {
							this.portComponents[i].data.index = this.multipleDelNum;
						} else if(this.portComponents[i].type == 'add') {
							this.portComponents[i].params = {
								pcd: this.vpcd,
								pcdname: this.vpcdname
							};
						} else {
							return;
						}
						return;
					}
				}
			},
			componentsHide(setting) { //关闭组件
//				this.multipleDeleteDisabled = true
				if(setting.type == "fladd") {
					this.portComponents.fladd.toggle = false;
					if(!setting.cancel) {
						//刷新分类
						this.getcomboxlist();
					}
				} else if(setting.type == "fledit") {
					this.portComponents.fledit.toggle = false;
					if(!setting.cancel) {
						//刷新分类
						this.getcomboxlist();
					}
				} else {

					for(let i in this.portComponents) {
						if(setting.type == this.portComponents[i].type) {
							this.portComponents[i].toggle = false;
							if(!setting.cancel) {
								this.search();
							}
							return;
						}
					}
				}
			}
		},
		computed: {
			...mapState([
				'api' //域名
			]),
			multipleDeleteDisabled() {
//				console.log(this.multipleDelNum)
				if(this.multipleDelNum) {
					return false;
				} else {
					return true
				}
			}
		}
	}
</script>

<style lang="less" scoped>
	.wpsz {
		font-size: 12px;
		.wpszlt {
			float: left;
			font-size: 12px;
			width: 25%;
			height: 100%;
			border: 1px solid #CCCCCC;
			/*margin-right: 10px;*/
		}
		.wpfl {
			width: 100%;
			height: 50px;
			float: left;
			background: #CCCCCC;
			font-size: 25px;
			font-weight: 700;
			text-align: center;
			line-height: 50px;
			border-bottom: 1px solid #CCCCCC;
		}
		.wpfltj {
			width: 100%;
			height: 50px;
			float: left;
			background: white;
			font-size: 16px;
			text-align: center;
			line-height: 50px;
			border-bottom: 1px solid #CCCCCC;
			cursor: pointer;
		}
		.jc {
			width: 100%;
			height: 50px;
			float: left;
			background: white;
			border-bottom: 1px solid #CCCCCC;
		}
		.jc2 {
			width: 100%;
			height: 50px;
			float: left;
			background: #71BFF4;
			border-bottom: 1px solid #CCCCCC;
		}
		.jc:hover {
			background: #C0CCDA;
		}
		.jclt {
			width: 100%;
			height: 50px;
			float: left;
			font-size: 14px;
			text-align: center;
			line-height: 50px;
			/*border-right: 1px solid #CCCCCC;*/
			cursor: pointer;
		}
		.port-page {
			font-size: 12px;
			width: 74%;
			float: right;
			border-left: 1px solid #CCCCCC;
			.wpsj {
				width: 100%;
				height: 50px;
				float: left;
				background: white;
				text-align: center;
				font-size: 20px;
				line-height: 50px;
				border-bottom: 1px solid #CCCCCC;
				border-top: 1px solid #CCCCCC;
				border-right: 1px solid #CCCCCC;
			}
			.btn {
				height: 30px;
				padding: 0 10px;
			}
			.code-search {
				max-width: 130px;
            min-width: 100px;
            text-align: center;
            height: 50px;
            /*line-height: 50px;*/
            font-size: 12px;
			}
			.class-page {
				text-align: left;
				margin-top: 10px;
			}
			.search-item {
				display: inline-block;
			}
			.but1 {
				width: 30%;
				float: left;
			    height: 50px;
			}
			.search {
			width: 68%;
			height: 50px;
			line-height: 50px;
			float: right;
			text-align: right;
		}
			.el-button+.el-button {
				margin-left: 0px;
			}
		}
	}
</style>